﻿using DreamCMS.BLL;
using DreamCMS.Entity;
using DreamCMS.Entity.Common;
using DreamCMS.WebCore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DreamCMS.Web
{
    public partial class post : FrontPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            InitCurrentTemplateContext();//初始化当前页面的模板标签上下文对象
            Display("post.html"); //展现页面
        }

        /// <summary>
        /// 初始化模板引擎辅助类
        /// 使用相关标签数据初始化模板辅助类中的NVelocity模板的标签上下文对象
        /// </summary>
        private void InitCurrentTemplateContext()
        {
            tplHelper.Put(DmTagsSet.IS_POST, "1");
            PostInfo post = null;
            string name = RequestHelper.GetQueryString("name", true);
            if(!StringHelper.IsUnsignedNum(name))
            {
                post=PostManager.GetPost(name);
            }
            else
            {
                post = PostManager.GetPost(StringHelper.ObjectToInt32(name,0));
            }
            if (post == null)
            {
                Response.Write("文章未找到，囧！没有找到此文章！");
                return;
            }

            if (post.Status == (int)PostStatus.Draft)
            {
                Response.Write("文章未发布，囧！此文章未发布！");
                return;
            }
            tplHelper.Put(DmTagsSet.POST, post);
            tplHelper.Put(DmTagsSet.PAGE_TITLE, post.Title);
            string metaKeywords = string.Empty;
            string metaDescription = post.Summary;
            if (string.IsNullOrEmpty(post.Summary))
            {
                metaDescription = post.Content;
            }
            tplHelper.Put(DmTagsSet.META_DESCRIPTION, StringHelper.CutString(StringHelper.RemoveHtml(metaDescription), 50,"").Replace("\n", ""));
            tplHelper.Put(DmTagsSet.CATEID, post.CategoryId);
        }

    }
}